package com.chuan.state;

public class TestStop implements Runnable{
    //设置标志位
    private boolean flag = true;
    @Override
    public void run() {
        int i = 0;
        while(flag){
            System.out.println("Thread:"+i++);
        }
    }
    //公开方法转换标志位
    public void stop(){
        this.flag = false;
    }

    public static void main(String[] args) {
        TestStop testStop = new TestStop();
        new Thread(testStop).start();
        for (int i = 0; i < 100; i++) {
            System.out.println("Main:"+i);
            if(i == 90){
                testStop.stop();
            }
        }
    }
}
